<?php
/**
 * Created by PhpStorm.
 * User: mr.lee
 * Date: 2018/7/4
 * Time: 下午12:03
 */

namespace app\common\controller;


use app\common\model\Agent;
use app\common\model\LoginUsers;
use app\common\model\Momerchant;
use think\Controller;
use think\Session;

class Manager extends Controller
{
    public function merchantlogin($top_mid)
    {
        if (!empty($top_mid)) {
            $map['username'] = Session::get('user.nickname');
            $LoginUser = new LoginUsers();
            $userinfo = $LoginUser->where($map)->find();

            if ($userinfo) {
                if ($userinfo['level'] == 2001) {
                    $mab['uid'] = $userinfo['id'];
                    $Agent = new Agent();
                    $agentinfo = $Agent->where($mab)->find();
                    $Momerchant = new Momerchant();
                    $momerchantinfo = $Momerchant->where(array('agent' => $agentinfo['id']))->find();
                    if ($momerchantinfo) {
                        Session::set('level', 3001);
                        Session::set('level2', $userinfo['level']);
                        Session::set('login_top_mid', $top_mid);
                        $data = array('result_code' => "SUCCESS", 'result_msg' => "SUCCESS");
                    } else {
                        $data = array('result_code' => "FAIL", 'result_msg' => "您没有权限访问该商户1");
                    }
                } else {
                    $data = array('result_code' => "FAIL", 'result_msg' => "您没有权限访问该商户2");

                }
            } else {
                $data = array('result_code' => "FAIL", 'result_msg' => "您没有权限访问该商户3");
            }
        } else {
            $data = array('result_code' => "FAIL", 'result_msg' => "非法访问");

        }
        return $data;


    }


}